-module(tools).
-export([mps_to_mph/1, mps_to_kph/1, absolute_value/1, product/1, average/1]).

mps_to_mph(Mps) -> 2.23693629 * Mps.

mps_to_kph(Mps) -> 
	Velocity = 3.6 * Mps,

	if
		( Velocity > 200.0 ) -> io:format("This is truly fast!~n");
		true -> true %% if must always find a tru status in condition.
	end,

	Velocity.
%% end.

%% @doc Calculates product of an list.
product([]) -> 0; % in case the list is empty, return zero
product(List) -> product(List,1).
product([], Product) -> Product;  % when list empty, stop, report
product([Head|Tail], Product) -> product(Tail, Product * Head).

%% @doc Calculates the average value of an array
average(List) -> sum(List) / len(List).

sum([]) -> 0;
sum([H|T]) -> H + sum(T).

len([]) -> 0;
len([_|T]) -> 1 + len(T). 

absolute_value(Number) when Number < 0  -> -Number;
absolute_value(Number) when Number == 0  -> 0;
absolute_value(Number) when Number > 0  -> Number.
